
package com.limoilux.cobolux.ui.console;

import java.io.IOException;

import org.eclipse.ui.console.IOConsole;
import org.eclipse.ui.console.IOConsoleOutputStream;

public class CoboluxConsole extends IOConsole
{
	private static CoboluxConsole SINGLETON = new CoboluxConsole();

	private CoboluxConsole()
	{
		super("Cobolux", null);

		try
		{
			this.getInputStream().close();
		}
		catch (IOException e)
		{
		}

	}

	public void write(String s) throws IOException
	{
		IOConsoleOutputStream io = this.newOutputStream();

		try
		{
			io.write(s);
		}
		finally
		{
			if (io != null)
			{
				io.flush();
				io.close();
				io = null;
			}
		}

	}

	public static CoboluxConsole getConsole()
	{
		return CoboluxConsole.SINGLETON;
	}
	
	public static void print(String s) throws IOException
	{
		CoboluxConsoleFactory factory = new CoboluxConsoleFactory();
		
		factory.openConsole();
		
		CoboluxConsole.SINGLETON.write(s);
	}
}
